package com.cloudlead.customerAction.service.impl.gps.util;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
/**
 * @author
 */
public class HttpGps {
	public String getGpsInfo0(String url ,String params) throws UnsupportedEncodingException, IOException{
		
        StringBuffer bufferRes = new StringBuffer();
        String str = null;
        try {
        	      URL realUrl = new URL(url);

                HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();

                // 连接超时

                conn.setConnectTimeout(25000);

                // 读取超时 --服务器响应比较慢,增大时间

                conn.setReadTimeout(25000);

                HttpURLConnection.setFollowRedirects(true);

                // 请求方式

                conn.setRequestMethod("GET");

                conn.setDoOutput(true);

                conn.setDoInput(true);

                conn.setRequestProperty("accept", "*/*");
                conn.setRequestProperty("connection", "Keep-Alive");
                conn.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
                conn.connect();

                // 获取URLConnection对象对应的输出流

                OutputStreamWriter out = new OutputStreamWriter((conn.getOutputStream()),"UTF-8");

                // 发送请求参数
         //       out.write(URLEncoder.encode(params,"UTF-8"));
               
                out.write(params);

                out.flush();

                out.close();

                InputStream in = conn.getInputStream();

                BufferedReader read = new BufferedReader(new InputStreamReader(in,"UTF-8"));

                String valueString = null;

                while ((valueString=read.readLine())!=null){

                        bufferRes.append(valueString);

                }

//                System.out.println(bufferRes.toString());
                str = bufferRes.toString();

                in.close();

                if (conn != null) {

                        // 关闭连接

                        conn.disconnect();

                }

        } catch (Exception e) {

                e.printStackTrace();

        }
        return str;
}
public static void main(String args[]) throws UnsupportedEncodingException, IOException{
        HttpGps fu = new HttpGps();
        System.out.println(fu.getGpsInfo0("http://mgps.shedi.com/getCarInfo.php?userid=jinghekj&password=jinghekj&encrypt=0&carno=","沪DD0477"));
}



}
